<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns:jsf="http://xmlns.jcp.org/jsf"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"> 
    <h:form>
        <input type="submit" value="Novo" class="button" jsf:action="${userManagedBean.openNew}" jsf:id="novo"/>
        <br/>
        <br/>    
        <fieldset>
            <legend> Consulta de Usuários </legend>
            <f:view>
                <h:panelGroup rendered="${not empty userManagedBean.list}">
                    <table class="tableConsulta">   
                        <thead>
                            <tr>
                                <td>
                                    Nome
                                </td>
                                <td>
                                    Login
                                </td>     
                                <td>
                                    Status
                                </td> 
                                <td>
                                    Editar
                                </td>                                     
                                <td>
                                    Ativar/Desativar
                                </td>                        
                            </tr>
                        </thead>
                        <ui:repeat value="${userManagedBean.list}" var="user">
                            <tr>
                                <td>
                                    ${user.name}
                                </td>
                                <td>
                                    ${user.loginName}
                                </td>                  
                                <td>
                                    ${user.userStatus.status}
                                </td> 
                                <td>
                                    <input type="submit" class="buttonEdit" value=""
                                           jsf:action="${userManagedBean.openToUpdate}"
                                           jsf:rendered='${user.name != "admin"}' jsf:id="editar">
                                        <f:param value="${user.id}" name="id"/>
                                    </input>
                                    
                                </td>
                                <td>
                                    <h:panelGroup rendered='${user.name != "admin"}'>
                                        <input type="submit" class="buttonDesactive" jsf:rendered="${user.userStatus.active}"
                                               jsf:action="${userManagedBean.deactive}" jsf:id="desativar">
                                            <f:param value="${user.id}" name="id"/>
                                        </input>
                                        <input type="submit" class="buttonActive"  jsf:rendered="${!user.userStatus.active}"
                                           jsf:action="${userManagedBean.active}" jsf:id="ativar">
                                            <f:param value="${user.id}" name="id"/>
                                        </input>
                                    </h:panelGroup>
                                </td>
                            </tr>                       
                        </ui:repeat>
                    </table>
                </h:panelGroup>    
            </f:view>
        </fieldset>    
    </h:form>
</html>

